<?php

namespace LDL\Twspider\C;

use LDL\Twspider\C\SpThreaded;
use LDL\Twspider\Spider;
use LDL\Twspider\TwWorker;
use LDL\Twspider\E\ConsoleLog;
use Symfony\Component\EventDispatcher\GenericEvent;

abstract class Taskrun extends SpThreaded{

    /**
     * @var TwWorker
     */
    //protected  $worker; in php7不能重复设置成员 
    /**
     * @var ConsoleLog
     */
    protected  $logger;
    public function  run(){
    	//$this->worker= $this->worker;
        $this->logger=$this->worker->spider->logger;
    }
    protected function dis($eventName, GenericEvent $event = null)
    {

        $disp = $this->worker->spider->getDispatcher();

        $disp->dispatch($eventName, $event);
    }
    public function forkTask($task,$workId=null){
//存入spider pool ?主spor再期
     //   $this->worker->topSpider->dump();
        $sp=$this->worker->topSpider;//这里拿到的对像是拷贝 如果去执行函数 有可能出问题

        //$pool=$this->worker->metaData['pool'];
        /**
         * @var $sp Spider
         * @var $pool \Pool
         */

       /* if($workId==null){
           $workId = $sp->workidIfNull();
        }*/

        if($task instanceof  Taskrun){
           // $sp->aaaa="xxx";
           /* $sp->dump();
            return $sp->forckTask($task,$workId);*/

        }else{
            $this->logger->error("task is not extends ".get_class(Taskrun::class));
        }
    }
}
